<?php
/**
 * 短网址
 * @author Tongle Xu <xutongle@gmail.com> 2013-9-24
 * @copyright Copyright (c) 2003-2103 tintsoft.com
 * @license http://www.tintsoft.com
 * @version $Id$
 */
class ShortUrl {
	private $http;
	public function __construct() {
		$this->http = new HttpClient ();
	}

	/**
	 * 创建短网址
	 *
	 * @param string $url 待缩短的网址
	 */
	public function create($url) {
		if(!$url) return false;
		$result = $this->http->post('http://dwz.cn/create.php', array ('url' => $url ));
		if ($result->code () == 200) {
			$res = $result->data ();
			return json_decode ( $res, true );
		}
		return false;
	}

	/**
	 * 还原短网址
	 *
	 * @param string $tinyurl 待还原的网址
	 */
	public function query($tinyurl) {
		if(!$tinyurl) return false;
		$result = $this->http->post('http://dwz.cn/query.php', array ('tinyurl' => $tinyurl ));
		if ($result->code () == 200) {
			$res = $result->data ();
			return json_decode ( $res, true );
		}
		return false;
	}
}